package com.mf.springboot.backend.commonModule.utils;

import com.xiaoleilu.hutool.crypto.SecureUtil;
import com.xiaoleilu.hutool.crypto.symmetric.AES;
import com.xiaoleilu.hutool.crypto.symmetric.DES;
import com.xiaoleilu.hutool.crypto.symmetric.SymmetricAlgorithm;
import sun.security.krb5.internal.crypto.Des;

/**
 * Created by lx on 2017/9/12.
 */
public class EncryptUtils {

    //随机生成密钥
    private static byte[] key = SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue()).getEncoded();

    //aes加密
    public static String encryptAes(String str){
        //构建
        AES aes = SecureUtil.aes(key);
        DES des = SecureUtil.des(key);
        //加密
        byte[] encrypt = aes.encrypt(str);
        //加密为16进制表示
        String encryptHex = des.encryptHex(str);
        return encryptHex;
    }

    //aes解密
    public static String decryptAes(String str){
        DES des = SecureUtil.des(key);
        //解密
        String decryptStr = des.decryptStr(str);
        return decryptStr;
    }

    public static void main(String[] args) {
        String a = encryptAes("123");
        String b = decryptAes(a);
        System.out.println(a);
        System.out.println(b);
    }
}
